from calibre.web.feeds.recipes import BasicNewsRecipe
     
class Git_Pocket_Guide(BasicNewsRecipe):
     
    title = 'Git Pocket Guide'
    description = ''
    cover_url = 'http://gitbook.liuhui998.com/assets/images/header-book.gif'
     
    url_prefix = 'http://gitbook.liuhui998.com/'
    no_stylesheets = True
    # keep_only_tags = [{ 'class': 'span-21' }]
     
    def get_title(self, link):
        return link.contents[0].strip()
     
    def parse_index(self):
        articles = []

        soup = self.index_to_soup(self.url_prefix + 'index.html')
        tag_td = soup.findAll('td')
        for volume in tag_td:
            if len(volume.contents) < 3:
                continue

            for link in volume.findAll('a'): 
                if not '.html' in link['href']:
                    continue
                til = self.get_title(link)
                url = self.url_prefix + link['href']
                a = { 'title': til, 'url': url }
         
                articles.append(a)

        ans = [('Git Community Book 中文版', articles)]
        return ans

        # div = soup.find('td')
         
        
        # for link in div.findAll('a'):
         
        #     if not '.html' in link['href']:
        #         continue
         
        #     til = self.get_title(link)
        #     url = self.url_prefix + link['href']
        #     a = { 'title': til, 'url': url }
         
        #     articles.append(a)
         
        
         
        # return ans